package com.certificationManager.client.presenter;

import com.certificationManager.client.CMEventBus;
import com.certificationManager.client.presenter.view_interface.IRootView;
import com.certificationManager.client.service.InitServiceAsync;
import com.certificationManager.client.view.RootView;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mvp4g.client.annotation.InjectService;
import com.mvp4g.client.annotation.Presenter;
import com.mvp4g.client.presenter.BasePresenter;

@Presenter( view = RootView.class )
public class RootPresenter extends BasePresenter<IRootView, CMEventBus>{
	
	/** Services */
	private InitServiceAsync initService = null;
	
	public void onChangeBody(Widget newPage){
		RootLayoutPanel body = view.getBody();
		body.clear(); // Attention, le conteneur doit étendre Widget (ce qui n'est pas le cas des classes de GXT).
		body.add(newPage);		
	}
	
	public void onStart(){
//		// On start, Init the DB.
//		initService.initDB(new AsyncCallback<Void>(){
//
//			@Override
//			public void onSuccess(Void result) {
//				Window.alert("INIT OK!");
//			}
//			@Override
//			public void onFailure(Throwable caught) {
//				Window.alert("INIT KO ><'...");
//			}
//			
//		});
//		
	}
	
	@InjectService
	public void setInitService( InitServiceAsync initService ) {
		this.initService = initService;
	}
	
}
